//
//  ViewController.m
//  SpecialEffectsProject
//
//  Created by 蓓蕾 on 2021/11/4.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _dataSource = [NSMutableArray arrayWithArray:@[
                   @{@"name":@"抽奖",@"navTitle":@"抽奖",@"vc":@"LuckDrawViewController"},
                   @{@"name":@"3D 球形",@"navTitle":@"旋转地球",@"vc":@"RotatingSphereViewController"},
                   @{@"name":@"时钟【类型一】",@"navTitle":@"时钟",@"vc":@"ClockTypeOneViewController"},
                   @{@"name":@"时钟【类型二】",@"navTitle":@"时钟",@"vc":@"ClockTypeTwoViewController"},
                   @{@"name":@"扫描",@"navTitle":@"扫描",@"vc":@"ScanningViewController"},
                   @{@"name":@"底部滑动视图",@"navTitle":@"滑动视图",@"vc":@"SliderViewController"},
                   @{@"name":@"底部滑动视图【类型二】",@"navTitle":@"滑动视图",@"vc":@"SliderTypeTwoViewController"},
                   @{@"name":@"底部滑动视图【类型三】",@"navTitle":@"滑动视图",@"vc":@"SliderTypeThreezViewController"},
                   @{@"name":@"底部滑动视图【类型四】",@"navTitle":@"滑动视图",@"vc":@"SliderTypeFourViewController"},
                   @{@"name":@"轮播图",@"navTitle":@"轮播图",@"vc":@"CycleScrollViewController"}]];
    [self initTableView];
}

-(void)initTableView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    _tableView.dataSource = self;
    _tableView.delegate = self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (indexPath.row < _dataSource.count) {
        NSDictionary *itemDic = _dataSource[indexPath.row];
        NSString *titleString = itemDic[@"name"];
        cell.textLabel.text = titleString;
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *itemDic = _dataSource[indexPath.row];
    NSString *navTitleString = itemDic[@"navTitle"];
    NSString *viewControllerString = itemDic[@"vc"];
    UIViewController *enterVC = [[NSClassFromString(viewControllerString) alloc] init];
    enterVC.navigationItem.title = navTitleString;
    [self.navigationController pushViewController:enterVC animated:YES];
}


@end
